package com.example.demo.rabbitmq.topic;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 鱼仔
 * @date 2021/7/1 5:20 下午
 * 创建一个简单模式的simple.test的队列
 */
@Configuration
public class TopicConfig {
    //创建一个交换机
    @Bean
    public TopicExchange createTopic() {
        return new TopicExchange("test.topic.exchange");
    }

    //创建fanout1.test的队列
    @Bean
    public Queue createTopic1Queue() {
        return new Queue("topic1.test");
    }

    //创建fanout2.test的队列
    @Bean
    public Queue createTopic2Queue() {
        return new Queue("topic2.test");
    }

    //绑定交换机和队列1
    @Bean
    public Binding topicBinding1(TopicExchange topicExchange, Queue createTopic1Queue) {
        return BindingBuilder.bind(createTopic1Queue).to(topicExchange).with("*.red.*");
    }

    // 绑定交换机和队列2
    @Bean
    public Binding topicBinding2(TopicExchange topicExchange, Queue createTopic2Queue) {
        return BindingBuilder.bind(createTopic2Queue).to(topicExchange).with("order.#");
    }
}
